package org.rulix.ogame.player.api;

import java.sql.Date;
import java.text.SimpleDateFormat;

import org.rulix.ogame.player.core.info.OGUnlocalizedStrings;
import org.rulix.ogame.player.core.info.OgameTagsTranslator;


public class OgameFleetMovement {
	public static enum OgameFleetMissionType {
		ATTACK,
		ATTACK_RETURN,
		TRANSPORT,
		TRANSPORT_RETURN,
		DEPLOYMENT,
		DEPLOYMENT_RETURN,
		ESPIONAGE,
		ESPIONAGE_RETURN, 
		INCOMING_ATTACK,
		INCOMING_ESPIONAGE,
	}

	private OgamePlanetCoordinates origin;
	private OgamePlanetCoordinates target;
	private OgameFleetMissionType missionType;
	private long arrivalTime;
	
	public void setOrigin(OgamePlanetCoordinates origin) {
		this.origin = origin;
	}
	
	public void setTarget(OgamePlanetCoordinates target) {
		this.target = target;
	}
	
	public OgamePlanetCoordinates getOrigin() {
		return origin;
	}
	
	public OgamePlanetCoordinates getTarget() {
		return target;
	}
	
	public void setMissionType(OgameFleetMissionType missionType) {
		this.missionType = missionType;
	}
	
	public OgameFleetMissionType getMissionType() {
		return missionType;
	}
	
	public long getArrivalTime() {
		return arrivalTime;
	}
	
	public void setArrivalTime(long arrivalTime) {
		this.arrivalTime = arrivalTime;
	}
	
	public void setMissionFromLocalizedString(String localizedString){
		OGUnlocalizedStrings ous = OGUnlocalizedStrings.valueOf(OgameTagsTranslator.getUnlocalizedString(localizedString));
		
		switch (ous) {
		case MISSION_TRANSPORT:
			missionType = OgameFleetMissionType.TRANSPORT;
			break;

		case MISSION_TRANSPORT_RETURN:
			missionType = OgameFleetMissionType.TRANSPORT_RETURN;
			break;

		case MISSION_ATTACK:
			missionType = OgameFleetMissionType.ATTACK;
			break;
			
		case MISSION_ATTACK_RETURN:
			missionType = OgameFleetMissionType.ATTACK_RETURN;
			break;
			
		case MISSION_ESPIONAGE:
			missionType = OgameFleetMissionType.ESPIONAGE;
			break;
			
		case MISSION_ESPIONAGE_RETURN:
			missionType = OgameFleetMissionType.ESPIONAGE_RETURN;
			break;
		case MISSION_INCOMING_ATTACK:
			missionType = OgameFleetMissionType.INCOMING_ATTACK;
			break;
		case MISSION_DEPLOYMENT:
			missionType = OgameFleetMissionType.DEPLOYMENT;
			break;
		case MISSION_DEPLOYMENT_RETURN:
			missionType = OgameFleetMissionType.DEPLOYMENT_RETURN;
			break;
		default:
			missionType = null;
			break;
		}
	}
	
	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd - HH.mm.ss");
		
		sb.append(String.format("[%20s|", missionType));
		sb.append(String.format("%10s| --> ", origin));
		sb.append(String.format("%10s|", target));
		sb.append(String.format("%21s]", sdf.format(new Date(arrivalTime))));
		
		return sb.toString();
	}
	
}
